#include <iostream>
#include <algorithm>
using namespace std;
const int N=1e5+10;

int a[N];

int main()
{
	int n,x;
	cin>>n>>x;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n);
	int left=1,right=1;
	int ret=0;
	while(right<=n)
	{
		while(left<=right && a[left]<a[right]-x)
		{
			left++;
		}
		ret=max(ret,right-left+1);
		right++;
	}
	cout<<ret<<endl;
	
	return 0;
}
